home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Add-Ons / HyperCard / OptKeyDown XFCN 1.0.2 / OptKeyDown.c < prev    next >
C/C++ Source or Header  |  1996-07-07  |  2KB  |  76 lines

  1. /* ----------------------------------------------------------------------
  2.  
  3.     OptionKeyDown XFCN
  4.     version 1.0.2
  5.     
  6.     Written by: Paul Celestin
  7.     
  8.     Copyright © 1993-1995 Celestin Company, Inc.
  9.     
  10.     This XFCN returns true if the option key is down.
  11.     
  12.     No parameters required!
  13.     
  14.     930927 - 1.0.0 - initial release
  15.     951215 - 1.0.1 - updated for CW7
  16.     960704 - 1.0.2 - updated for CW9
  17.  
  18. ---------------------------------------------------------------------- */
  19.  
  20. #include <A4Stuff.h>
  21. #include <HyperXCmd.h>
  22.  
  23. #define PARAMETER_NUMS        0
  24. #define PARAMETER_TEXT        "\pNo parameters required!"
  25.  
  26.  
  27. /* ----------------------------------------------------------------------
  28. prototypes
  29. ---------------------------------------------------------------------- */
  30. void DoIt(XCmdPtr paramPtr);
  31. Boolean BitTest(Ptr p, int n);
  32.  
  33.  
  34. /* ----------------------------------------------------------------------
  35. main
  36. ---------------------------------------------------------------------- */
  37. pascal void main(XCmdPtr paramPtr)
  38. {
  39.     Str255 copyright = "\pCopyright © 1993-1996 Celestin Company, Inc.";
  40.     long oldA4 = SetCurrentA4();
  41.     if (paramPtr->paramCount != PARAMETER_NUMS)
  42.     {
  43.         paramPtr->returnValue =
  44.             PasToZero(paramPtr,PARAMETER_TEXT);
  45.     }
  46.     else
  47.     {
  48.         DoIt( paramPtr );
  49.     }
  50.     SetA4(oldA4);
  51. }
  52.  
  53. /* ----------------------------------------------------------------------
  54. DoIt
  55. ---------------------------------------------------------------------- */
  56. void DoIt(XCmdPtr paramPtr)
  57. {
  58.     KeyMap        myKeys;
  59.  
  60.     GetKeys(myKeys);
  61.     if (BitTest((Ptr)myKeys, 0x3a)) /* 0x3a is the option key */
  62.         paramPtr->returnValue = PasToZero(paramPtr,"\ptrue");
  63.     else
  64.         paramPtr->returnValue = PasToZero(paramPtr,"\pfalse");
  65.  
  66. }
  67.  
  68.  
  69. /* ----------------------------------------------------------------------
  70. BitTest
  71. ---------------------------------------------------------------------- */
  72. Boolean BitTest(Ptr p, int n)
  73. {
  74.     return(!!(p[n/8] & 1L<<(n%8)));
  75. }
  76.